//
//  AudioManager.h
//  ImageToSound
//
//  Created by jvmilazz on 9/28/11.
//  Copyright 2011 ASU. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioFile.h>
#import <AudioToolbox/AudioToolbox.h>

//asdfasdfasdf
//asdfasdfasdf
//asdfasdfasdf
//asdfasdfasdfasdfasdfasdfasdf
//asdfasdf
//asdfasdfasdf

#define NUM_BUFFERS 3
#define SECONDS_TO_RECORD 10

typedef struct
{
    AudioStreamBasicDescription  dataFormat;
    AudioQueueRef                queue;
    AudioQueueBufferRef          buffers[NUM_BUFFERS];
    AudioFileID                  audioFile;
    SInt64                       currentPacket;
    bool                         recording;    
} RecordState;

typedef struct
{
    AudioStreamBasicDescription  dataFormat;
    AudioQueueRef                queue;
    AudioQueueBufferRef          buffers[NUM_BUFFERS];
    AudioFileID                  audioFile;
    SInt64                       currentPacket;
    bool                         playing;
} PlayState;

typedef struct RGBPixel {
    
    Byte    red;
    Byte    green;
    Byte    blue;
    
}   RGBPixel;

@class AudioManager;

@interface AudioManager : NSObject
{
    
    RecordState recordState;
    PlayState playState;
    CFURLRef fileURL;
    IBOutlet UILabel* statusLabel;
    IBOutlet UIButton* playButton;
    IBOutlet UIButton* recordButton;
    AudioComponentInstance toneUnit;
    
@public
    double theta;
    int curPixel;

} 

@property (nonatomic) CFURLRef fileURL;
@property (nonatomic) PlayState playState;
@property (nonatomic) RecordState recordState;
@property (nonatomic, retain) UILabel* statusLabel;
@property (nonatomic, retain) UIButton* playButton;
@property (nonatomic, retain) UIButton* recordButton;
@property (nonatomic) CGSize imageSize;
@property (nonatomic) RGBPixel * imageData;

- (BOOL)getFilename:(char*)buffer maxLenth:(int)maxBufferLength;
- (void)setupAudioFormat:(AudioStreamBasicDescription*)format;
- (IBAction)recordPressed:(id)sender;
- (IBAction)playPressed:(id)sender;
- (void)startRecording;
- (void)stopRecording;
- (void)startPlayback;
- (void)stopPlayback;
- (void)createWAVFile:(RGBPixel*)imageData withImageSize:(CGSize)imageSize;
- (void)createToneUnit;


@end
